import { defineStore } from "pinia";

import { getPageListData } from "../service/api/system";

import localCache from "@/utils/cache";

const useAllDataStore = defineStore("all", {
  state: () => {
    return {
      roleList: [],
      roleCount: 0,
      departmentList: [],
      departmentCount: 0,
    };
  },
  actions: {
    async getAllDataList(pageName) {
      const pageUrl = `/${pageName}/list`;
      const pageResult = await getPageListData(pageUrl, {});
      const { list, totalCount } = pageResult.data;

      this[`${pageName}List`] = list;
      this[`${pageName}Count`] = totalCount;

      localCache.setItem(`${pageName}List`, list);
      // localCache.setItem(`${pageName}Count`, totalCount);
    },
    loadLocalAllDataList(pageName) {
      this[`${pageName}List`] = localCache.getItem(`${pageName}List`);
      // this[`${pageName}Count`] = localCache.getItem(`${pageName}Count`);
    },
  },
  getters: {},
});

export default useAllDataStore;
